package ai.yale.util;

import java.lang.reflect.Field;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by chenmingfa on 2017/8/4.
 */
public class CheckUtils {

    // 检测是否存在空字段
    public static boolean hasEmptyFields(Object obj) {
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                if (field.get(obj) == null) {
                    return true;
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                return true;
            }
//            if (field.getType().getName().equals("java.lang.String")) {
//                if (StringUtils.isEmpty(field.get(obj))) {
//                    return false;
//                }
//            }
        }
        return false;
    }
    // 校验是否为正确的手机号
    public static boolean isCellPhoneNumber(String phone) {
        String regExp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$";
        Pattern p = Pattern.compile(regExp);
        Matcher m = p.matcher(phone);
        return m.matches();
    }
    // 校验用户名是否合法
    public static boolean isLegelUsername(String username) {
        String regex = "([a-z]|[A-Z]||[\\u4e00-\\u9fa5])+";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(username);
        return m.matches();
    }

    public static void main(String[] args) {
    }

}


